{template 'common/header'}
<style type="text/css">
	.require{color:red;}
	.info{padding:6px;width:400px;margin:-20px auto 3px auto;text-align:center;}
</style>
<ul class="nav nav-tabs">
	<li{if $op == 'list'} class="active"{/if}><a href="{php echo $this->createWebUrl('sms', array('op' => 'list'))}">短信模板列表</a></li>
	<li{if $op == 'post' && !$id} class="active"{/if}><a href="{php echo $this->createWebUrl('sms', array('op' => 'post'))}">添加短信模板</a></li>
	{if $id}<li class="active"><a href="#">编辑短信模板</a></li>{/if}
</ul>
{if $op == 'post'}
	<form class="form-horizontal form" id="form1" action="" method="post" enctype="multipart/form-data">
		<input type="hidden" name="reid" value="{$reid}">
		<input type="hidden" name="weid[]" value="{$weid}">
		<div class="main">
			<div class="panel panel-default">
				<div class="panel-heading">添加短信模板</div>
				<div class="panel-body">
					<div id="tpl">
						<div class="form-group">
							<label class="col-xs-12 col-sm-3 col-md-2 control-label">模板标题：</label>
							<div class="col-sm-9 col-xs-12">
								<input type="text" class="form-control" name="title[]" value="">
							</div>
						</div>
						<div class="form-group">
							<label class="col-xs-12 col-sm-3 col-md-2 control-label">{$appid}：</label>
							<div class="col-sm-9 col-xs-12">
								<input type="text" class="form-control" name="appid[]" value="" placeholder="{if $setting['sms']['mode']=='0'}应用管理 - 应用列表 - 【管理】 中获得{/if}">
							</div>
						</div>
						<div class="form-group">
							<label class="col-xs-12 col-sm-3 col-md-2 control-label">{$templateid}：</label>
							<div class="col-sm-9 col-xs-12">
								<input type="text" class="form-control" name="templateid[]" value="" placeholder="{if $setting['sms']['mode']=='0'}应用管理 - 短信管理 中获得{/if}">
							</div>
						</div>
						<hr>
					</div>
					<div id="tpl-container"></div>
					<div class="form-group">
						<label class="col-xs-12 col-sm-3 col-md-2 control-label"></label>
						<div class="col-sm-9 col-xs-12" style="padding-top:7px">
							<a href="javascipt:;" id="post-add"><i class="fa fa-plus-circle"></i> 继续添加</a>
						</div>
					</div>
				</div>
			</div>
			<div class="form-group">
				<div class="col-sm-9 col-xs-9 col-md-9">
					<input type="hidden" name="token" value="{$_W['token']}">
					<input name="submit" id="submit" type="submit" value="提交" class="btn btn-primary col-lg-1">
				</div>	
			</div>
		</div>
	</form>
	<script type="text/javascript">
		require(['util'], function(u){
			$('#post-add').click(function(){
				$('#tpl-container').append($('#tpl').html());
			});
		});
	</script>
{elseif $op == 'list'}
<style type="text/css">
.status-toggle{cursor:pointer;}
.white{color:#fff;}
</style>
	<div class="main">
		<div class="panel panel-info">
			<div class="panel-heading">筛选</div>
			<div class="panel-body">
				<form action="./index.php" method="get" class="form-horizontal" role="form">
					<input type="hidden" name="c" value="site">
					<input type="hidden" name="a" value="entry">
					<input type="hidden" name="m" value="dayu_sms">
					<input type="hidden" name="do" value="sms"/>
					<input type="hidden" name="op" value="list"/>
					<div class="form-group clearfix">
						<label class="col-xs-12 col-sm-2 col-md-2 col-lg-1 control-label">{$appid}</label>
						<div class="col-sm-7 col-lg-8 col-md-8 col-xs-12">
							<input class="form-control" name="keyword" id="" type="text" value="{$_GPC['keyword']}">
						</div>
						<div class="col-xs-12 col-sm-3 col-md-2 col-lg-1">
							<button class="btn btn-default"><i class="fa fa-search"></i> 搜索</button>
						</div>
					</div>
				</form>
			</div>
		</div>
				<div class="alert alert-info" style="width:100%:">
				<button type="button" class="close" data-dismiss="alert">×</button>
				<h4><i class="fa fa-comment-o" style="font-size:2rem"></i> 提示：<span class="text-danger">当前短信接口为【 {$mode} 】</span></h4>
				{if $setting['sms']['mode']==1}
				验证码模板：尊敬的${ptname}用户，您好。您的验证码是${code}，请注意查收！<br>
				注意：product变量为ptname<br>
				<span class="text-danger">阿里大于当前只支持验证码，不支持发送通知</span>
				{else}
				手机验证码模板：欢迎注册{1}会员，您的验证码是：{2} /或/ {1}此次的手机验证码是{2} （{1}=公众号名称）<br>
				通知类短信模板：有新订单，客户：{1}，手机：{2}，内容：{3} /或/ 有新订单，客户：{1}，手机：{2}，标题：{3}
				{/if}
				</div>
		<form class="form-horizontal" action="" method="post" enctype="multipart/form-data">
			<div class="panel panel-default">
				<div class="panel-body table-responsive">
					<table class="table table-hover">
						<thead class="navbar-inner">
							<tr>
								<th>标题：</th>
								<th style="width:150px;">接口：</th>
								<th>{$appid}：</th>
								<th>{$templateid}：</th>
								<th>验证码：</th>
								<th style="width:80px; text-align:right;">操作</th>
							</tr>
						</thead>
						<tbody>
							{loop $lists $item}
							<tr {if $item['openid'] == $activity['kfid']}style="background-color:#fff8e1;"{/if}>
								<input type="hidden" name="ids[]" value="{$item['id']}">
								<input type="hidden" name="weid[]" value="{$weid}">
								<td><input type="text" name="title[]" class="form-control" value="{$item['title']}"></td>
								<td>
									<select name="mode[]" class='form-control'>
										<option value="0" {if $item['mode'] == '0'}selected="selected"{/if}>随系统参数设置</option>
										<option value="1" {if $item['mode'] == '1'}selected="selected"{/if}>云之讯</option>
										<option value="2" {if $item['mode'] == '2'}selected="selected"{/if}>阿里大于</option>
										<!--
										<option value="3" {if $item['mode'] == '3'}selected="selected"{/if}>阿里云短信</option>
										-->
									</select>
							</td>
								<td><input type="text" name="appid[]" class="form-control" value="{$item['appid']}"></td>
								<td><input type="text" name="templateid[]" class="form-control" value="{$item['templateid']}"></td>
								<td>							
									<a data="{$item['num']}" href="javascript:;" class="btn btn-default {if $item['num']==1}btn-primary{/if}" onclick="setStatus(this,{$item['id']},'num','sms')">{if $item['num']==1}6位{else}4位{/if}</a>		
								</td>
								<td style="text-align:right;">
									<a href="{php echo $this->createWebUrl('sms', array('op' => 'smsdel', 'id' => $item['id']))}" class="btn btn-default btn-sm" title="删除" data-toggle="tooltip" data-placement="top" onclick="if(!confirm('删除短信模板，确定删除吗?')) return false;"><i class="fa fa-times"> </i></a>
								</td>
							</tr>
							{/loop}
						</tbody>
					</table>
				</div>
			</div>
			<div class="form-group">
				<div class="col-sm-9 col-xs-9 col-md-9">
					<input type="hidden" name="token" value="{$_W['token']}">
					<input name="submit" id="submit" type="submit" value="批量修改" class="btn btn-primary">
				</div>	
			</div>
			{$pager}
		</form>
	</div>
<script>
	function setStatus(obj,id,type,table){
		$(obj).html($(obj).html() + "...");
		$.post("{php echo $this->createWebUrl('ajaxset')}",{id:id,type:type,table:table, data: obj.getAttribute("data")},function(d){
			$(obj).html($(obj).html().replace("...",""));
			if(type=='num'){
				$(obj).html( d.data=='1'?'6位':'4位');
			}
			$(obj).attr("data",d.data);
			if(d.result==1){
				$(obj).toggleClass("btn-primary");
			}
		},"json");
	}
	require(['bootstrap'],function($){
		$('.btn').hover(function(){
			$(this).tooltip('show');
		},function(){
			$(this).tooltip('hide');
		});
	});
</script>
{/if}
{template 'common/footer'}